<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .head {
        width: 400px;
        height: 400px;
        background: burlywood;
    }

    .AAA {
        width: 100px;
        height: 100px;
    }
</style>

<body>
    <div class="js-body head">单击我</div>
    <div class="js-fead AAA">单机成功</div>
    <script>

        let body = document.querySelector(".js-body")
        let div = document.querySelector(".js-fead")

        console.log(body);
        console.log(div);

        body.addEventListener('click', function (e) {
            if (div.classList.contains('AAA')) {
                fadeIn(div);
            } else {
                fadeOut(div);
            }
        });

        console.log(div.classList);

        function fadeIn(div, display) {
            if (div.classList.contains('AAA')) {
                div.classList.remove('AAA');
            }
            div.style.opacity = 0;
            div.style.display = display || "block";
            div.style.background= "cadetblue";
            div.style.width = 300 + "px";
            div.style.height = 300 + "px";
            
            (function fade() {
                var val = parseFloat(div.style.opacity);
                if (!((val += .1) > 1)) {
                    div.style.opacity = val;
                    requestAnimationFrame(fade);
                }
            })();
        }

        function fadeOut(div) {
            div.style.opacity = 1;

            (function fade() {
                if ((div.style.opacity -= .1) < 0) {
                    div.style.display = 'none';
                    div.classList.add('AAA');
                } else {
                    requestAnimationFrame(fade);
                }
            })();
        }

        body.onclick = function () {

            fadeIn(div, 0, 6000)
            fadeOut(div, 0, 6000)
            console.log(11111);
            // alert("AAA")
        }
    </script>
</body>

</html>